import {dicData} from '@/api/adminapp'
export const setDictMap = () => {
    const dictDataMap = {}
    dicData(res => {
        res.data.forEach((dictData) => {
            // 获得 dictType 层级
            const enumValueObj = dictDataMap[dictData.dictType]
            if (!enumValueObj) {
                dictDataMap[dictData.dictType] = []
            }
            // 处理 dictValue 层级
            dictDataMap[dictData.dictType].push({
                value: dictData.value,
                label: dictData.label,
                colorType: dictData.colorType,
                cssClass: dictData.cssClass
            })
        })
        localStorage.setItem('DIC_DATA', JSON.stringify(dictDataMap))
    })
}
export const getDictOptions = (dictType) => {
    const dicDataAll = JSON.parse(localStorage.getItem('DIC_DATA'))
    return dicDataAll[dictType] || []
}

export const getDictOptionsValue = (dictType, value) => {
    const dicDataAll = JSON.parse(localStorage.getItem('DIC_DATA'))
    const dicTypeData = dicDataAll[dictType] || []
    const filterList = dicTypeData.filter(e => e.value == value)
    if(filterList.length) {
        return filterList[0].label
    } else {
        return ''
    }
}
